package net.jlibrary.group.action;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import net.jlibrary.common.CoreConstants;
import net.jlibrary.common.core.annotation.Token;
import net.jlibrary.common.core.entity.Pagination;
import net.jlibrary.common.core.entity.PaginationParam;
import net.jlibrary.group.action.vo.ParkingPlaceTypeAdminActionVo;
import net.jlibrary.group.service.IParkingPlaceTypeManager;

import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping("/group")
public class ParkingPlaceTypeAdminAction {
	@Resource
	private IParkingPlaceTypeManager parkingPlaceTypeManager;
	
	@RequestMapping(value = "/parkingPlaceTypeAdminView", method = {RequestMethod.GET})
	public ModelAndView view() {
		return new ModelAndView("/group/parkingPlaceTypeAdminView");
	}
	@RequestMapping(value = "/parkingPlaceTypeAdminJsonList", method = {RequestMethod.POST})
	public Pagination lists(ParkingPlaceTypeAdminActionVo parkingPlaceType ,PaginationParam param) {
		Pagination pagination = parkingPlaceTypeManager.listsPageDictionarys(parkingPlaceType, param);
		return pagination;
	}
	@RequestMapping(value = "/parkingPlaceTypeAdminJsonDetail", method = {RequestMethod.GET})
	public ParkingPlaceTypeAdminActionVo detail(ParkingPlaceTypeAdminActionVo parkingPlaceType) {
		parkingPlaceType =  parkingPlaceTypeManager.get(parkingPlaceType);
		return parkingPlaceType;
	}
	@RequestMapping(value = "/parkingPlaceTypeAdminJsonAddFormInit", method = {RequestMethod.GET})
	public ParkingPlaceTypeAdminActionVo addFormInit() {
		ParkingPlaceTypeAdminActionVo parkingPlaceType = new ParkingPlaceTypeAdminActionVo();
		return parkingPlaceType;
	}
	@RequestMapping(value = "/parkingPlaceTypeAdminJsonSave", method = {RequestMethod.POST})
	@Token
	public ModelMap save(@ModelAttribute("vm") ParkingPlaceTypeAdminActionVo parkingPlaceType, @Token String token, BindingResult result) {
		parkingPlaceTypeManager.save(parkingPlaceType);
		ModelMap map = new ModelMap();
		map.put("success", true);
		return map;
	}
	
	@RequestMapping(value = "/parkingPlaceTypeAdminJsonUpdate", method = {RequestMethod.POST})
	@Token
	public ModelMap update(@ModelAttribute("vm") ParkingPlaceTypeAdminActionVo parkingPlaceType, @Token String token, BindingResult result) {
		parkingPlaceTypeManager.update(parkingPlaceType);
		ModelMap map = new ModelMap();
		map.put("success", true);
		return map;
	}
	
	@RequestMapping(value = "/parkingPlaceTypeAdminJsonDelete", method = {RequestMethod.POST})
	public ModelMap delete(Long id) {
		ParkingPlaceTypeAdminActionVo parkingPlaceType = new ParkingPlaceTypeAdminActionVo();
		parkingPlaceType.setId(id);
		parkingPlaceTypeManager.delete(parkingPlaceType);
		ModelMap map = new ModelMap();
		map.put("success", true);
		return map;
	}
	
	@RequestMapping(value = "/parkingPlaceTypeAdminJsonRenew", method = {RequestMethod.POST})
	public ModelMap renew(Long id) {
		ParkingPlaceTypeAdminActionVo parkingPlaceType = new ParkingPlaceTypeAdminActionVo();
		parkingPlaceType.setId(id);
		parkingPlaceTypeManager.renew(parkingPlaceType);
		ModelMap map = new ModelMap();
		map.put("success", true);
		return map;
	}
	
	@RequestMapping(value = "/parkingPlaceTypeAdminJsonData", method = {RequestMethod.GET})
	public List<ModelMap> parkingPlaceTypeAdminData() {
		List<ParkingPlaceTypeAdminActionVo> parkingPlaceTypes = parkingPlaceTypeManager.listDictionarys(new ParkingPlaceTypeAdminActionVo());
		List<ModelMap> maps = new ArrayList<ModelMap>();
		for (ParkingPlaceTypeAdminActionVo parkingPlaceType : parkingPlaceTypes) {
			ModelMap map = new ModelMap();
			map.put(CoreConstants.VIEW_SELECT_LABEL_VALUE, parkingPlaceType.getPrimaryKey());
			map.put(CoreConstants.VIEW_SELECT_LABEL_TEXT, parkingPlaceType.getText());
			maps.add(map);
		}
		return maps;
	}
}
